package com.chuisha.stu.controller;

import com.chuisha.common.CommonResult;
import com.chuisha.stu.service.AccountService;
import com.chuisha.stu.service.AccountFeign;
import com.chuisha.stu.service.vo.AccountVO;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Log4j2
public class AccountController implements AccountFeign {
    @Autowired
    private AccountService accountService;

    @Override
    public CommonResult<AccountVO> getByCode(@PathVariable String accountCode) {
        log.info("get account detail,accountCode is :{}", accountCode);
        return CommonResult.success(accountService.selectByCode(accountCode));
    }

    @Override
    public CommonResult<AccountVO> update(AccountVO accountVO) {
        log.info("update account:{}", accountVO);
        return CommonResult.success(accountService.updateAccount(accountVO));
    }

    @Override
    public CommonResult<AccountVO> insert(AccountVO accountVO) {
        log.info("insert account:{}", accountVO);
        return CommonResult.success(accountService.insertAccount(accountVO));
    }

    @Override
    public CommonResult<Integer> delete(@RequestParam String accountCode) {
        log.info("delete account,accountCode is {}", accountCode);
        return CommonResult.success(accountService.deleteAccount(accountCode));
    }
}